import { validateInput, validateLabel } from './validate'
import { i18n } from '@/lang'

export function rules() {
  return {
    label: [
      {
        required: true,
        message: i18n.t('flyparam.input_enter_tip'),
        trigger: 'blur'
      },
      { validator: validateLabel, trigger: ['blur', 'change'] }
    ],
    key: [
      {
        required: true,
        message: i18n.t('flyparam.input_enter_tip')
      },
      { validator: validateInput, trigger: ['blur', 'change'] }
    ],
    valueType: [
      {
        required: true,
        message: i18n.t('flyparam.input_enter_tip'),
        trigger: 'blur'
      }
    ],
    table: [
      {
        required: true,
        message: i18n.tt('flyparam.input_enter_tip'),
        trigger: 'blur'
      }
    ],
    formatter: [
      {
        required: true,
        message: i18n.tt('flyparam.input_enter_tip')
      }
    ],
    title: [
      {
        validator: (rule, value, callback) => {
          if (value && value.length > 64) {
            return callback(new Error(i18n.tt('flyparam.length_exceeds')))
          }
          callback()
        }
      }
    ]
  }
}

export function layoutRules() {
  return {}
}
